﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

namespace WebApplication1
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox2.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + Button7.UniqueID + "').click();return false;}} else {return true}; ");
            TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + Button7.UniqueID + "').click();return false;}} else {return true}; ");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:62505/Default.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:62505/Menu.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:62505/Aboutus.aspx");
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:62505/Contact.aspx");
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:62505/Map.aspx");
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:62505/Login.aspx");
        }

        private OleDbConnection accessconn;
        
        protected void Button7_Click(object sender, EventArgs e)
        {
            accessconn = new OleDbConnection();
            accessconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                                @"C:\Dbase_SEA\myDB.accdb";
            accessconn.Open();
            DataSet ds = new DataSet();
            string query1 = "select Eid, Ename, Password from Employee";
            OleDbDataAdapter da = new OleDbDataAdapter(query1,accessconn);
            da.Fill(ds);
            bool stat = false;
            //Checks for the employee id and password from the Employee table
            for(int r = 0; r < ds.Tables[0].Rows.Count; r++) 
            {
                string eid = ds.Tables[0].Rows[r]["Eid"].ToString();
                string pass = ds.Tables[0].Rows[r]["Password"].ToString();
                if (eid.Equals(TextBox1.Text) && pass.Equals(TextBox2.Text))
                {
                    stat = true;
                    string ename = ds.Tables[0].Rows[r]["Ename"].ToString();
                    Response.Redirect("http://localhost:62505/MenuOrder.aspx?empname="+ename+"&eid="+eid);
                }
            }
            if (stat == false)
            {
                MessageBox("Invalid Login");
            }
            accessconn.Close();
        }
        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }

    }
}
